package hl.crazy_java.chapter_18.reflect;

import hl.crazy_java.chapter_18.Person;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;

/**
 * 
 * @author Liu Huan
 */


public class demoConstructor {
	/**
	 1、获取成员变量们
	 Field getField(String name)
	 Field[] getFields()
	 Field getDeclaredField(String name)
	 Field[] getDeclaredFields()
	 2、获取成员方法们
	 Method getMethod(String name, Class<?>... parameterTypes)
	 Method[] getMethods()
	 Method getDeclaredMethod(String name, Class<?>... parameterTypes)
	 Method[] getDeclaredMethods()
	 Method getEnclosingMethod()
	 3、获取构造器们
	 Constructor<T>getConstructor(Class<?>... parameterTypes)	
	 Constructor<?>[]getConstructors()
	 Constructor<T>getDeclaredConstructor(Class<?>... parameterTypes)
	 Constructor<?>[]getDeclaredConstructors()
	 Constructor<?>getEnclosingConstructor()
	 4、获取类名，包名
	 String getName()
	 String getPackageName()
	 */
	public static void main(String[] args) throws Exception {
		//获取 Class 对象
		Class<Person> personClass = Person.class;
		
		//获取 任一修饰的 所有构造器 并打印
		Constructor<?>[] declaredClasses = personClass.getDeclaredConstructors();
		for (Constructor<?> declaredClass : declaredClasses) {
			System.out.println(declaredClass);
		}
		
		//获取 任一修饰的 指定参数的 构造器
		Constructor declaredConstructor = personClass.getDeclaredConstructor(String.class, int.class);
		//创建对象 并打印
		Object obj = declaredConstructor.newInstance("liu", 22);
		System.out.println(obj);
	}
}
